<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>Sass内置函数 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="内置函数（字符串函数，数字函数等）  自定义函数使用方法   数字相关函数   函数名及参数 作用    percentage($number) 转换成百分比   round($number) 执行标准舍入，即它总是将数值四舍五入为最接近的整数   ceil($number) 执行向上舍入，即它总是将数值向上取整   floor($number) 向下取整   abs($number) 获取绝">
<meta name="keywords" content="Sass">
<meta property="og:type" content="article">
<meta property="og:title" content="Sass内置函数">
<meta property="og:url" content="http://yoursite.com/2019/10/25/Sass内置函数/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="内置函数（字符串函数，数字函数等）  自定义函数使用方法   数字相关函数   函数名及参数 作用    percentage($number) 转换成百分比   round($number) 执行标准舍入，即它总是将数值四舍五入为最接近的整数   ceil($number) 执行向上舍入，即它总是将数值向上取整   floor($number) 向下取整   abs($number) 获取绝">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2019-10-25T02:51:06.978Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Sass内置函数">
<meta name="twitter:description" content="内置函数（字符串函数，数字函数等）  自定义函数使用方法   数字相关函数   函数名及参数 作用    percentage($number) 转换成百分比   round($number) 执行标准舍入，即它总是将数值四舍五入为最接近的整数   ceil($number) 执行向上舍入，即它总是将数值向上取整   floor($number) 向下取整   abs($number) 获取绝">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Sass内置函数" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/10/25/Sass内置函数/" class="article-date">
  <time datetime="2019-10-25T01:54:01.000Z" itemprop="datePublished">2019-10-25</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Sass/">Sass</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Sass内置函数
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<ul>
<li><p>内置函数（字符串函数，数字函数等）</p>
</li>
<li><p>自定义函数使用方法</p>
</li>
</ul>
<h2 id="数字相关函数"><a href="#数字相关函数" class="headerlink" title="数字相关函数"></a>数字相关函数</h2><table>
<thead>
<tr>
<th>函数名及参数</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>percentage($number)</td>
<td>转换成百分比</td>
</tr>
<tr>
<td>round($number)</td>
<td>执行标准舍入，即它总是将数值四舍五入为最接近的整数</td>
</tr>
<tr>
<td>ceil($number)</td>
<td>执行向上舍入，即它总是将数值向上取整</td>
</tr>
<tr>
<td>floor($number)</td>
<td>向下取整</td>
</tr>
<tr>
<td>abs($number)</td>
<td>获取绝对值</td>
</tr>
<tr>
<td>min($number…)</td>
<td>获取最小值</td>
</tr>
<tr>
<td>max($number…)</td>
<td>获取最大值</td>
</tr>
<tr>
<td>random()</td>
<td>获得随机数</td>
</tr>
</tbody></table>
<h3 id="关于-random"><a href="#关于-random" class="headerlink" title="关于 random()"></a>关于 random()</h3><p>如果没有参数传入，random 会传入一个0~1的随机数（包括小数）</p>
<p>如果传入一个整数，比如10，会获得0~10的一个随机整数</p>
<p>不能传入一个小数</p>
<h2 id="数组相关函数"><a href="#数组相关函数" class="headerlink" title="数组相关函数"></a>数组相关函数</h2><table>
<thead>
<tr>
<th>函数名及参数</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>length($list)</td>
<td>获取数组长度</td>
</tr>
<tr>
<td>nth($list, $n)</td>
<td>获取指定下标的元素。下标从1开始</td>
</tr>
<tr>
<td>set-nth($list, $n, $value)</td>
<td>替换指定下标的元素</td>
</tr>
<tr>
<td>join($list1, $list2)</td>
<td>拼接数组</td>
</tr>
<tr>
<td>append($list1, $val, <code>[$separator]</code>)</td>
<td>从数组尾部添加元素</td>
</tr>
<tr>
<td>index($list, $value)</td>
<td>返回指定元素在数组中的位置</td>
</tr>
</tbody></table>
<h2 id="字符串相关函数"><a href="#字符串相关函数" class="headerlink" title="字符串相关函数"></a>字符串相关函数</h2><table>
<thead>
<tr>
<th>函数名及参数</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>unquote($string)</td>
<td>去除引号</td>
</tr>
<tr>
<td>quote($string)</td>
<td>添加引号</td>
</tr>
<tr>
<td>str-length($string)</td>
<td>获取字符串长度</td>
</tr>
<tr>
<td>str-insert($string, $insert, $index)</td>
<td>在指定位置插入字符串</td>
</tr>
<tr>
<td>str-index($string, $substring)</td>
<td>返回指定字符在字符串的位置</td>
</tr>
<tr>
<td>to-upper-case($string)</td>
<td>转换为大写</td>
</tr>
<tr>
<td>to-lower-case($string)</td>
<td>转换为小写</td>
</tr>
</tbody></table>
<h2 id="map-相关函数"><a href="#map-相关函数" class="headerlink" title="map 相关函数"></a>map 相关函数</h2><table>
<thead>
<tr>
<th>函数名及参数</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>map-get($map, $key)</td>
<td>根据给定的 key 值，返回 map 中相关的值</td>
</tr>
<tr>
<td>map-merge($map1, $map2)</td>
<td>将两个 map 合并成一个新的 map</td>
</tr>
<tr>
<td>map-remove($map, $key)</td>
<td>从 map 中删除一个 key，返回一个新 map</td>
</tr>
<tr>
<td>map-keys($map)</td>
<td>返回 map 中所有的 key</td>
</tr>
<tr>
<td>map-value($map)</td>
<td>返回 map 中所有的 value</td>
</tr>
<tr>
<td>map-has-key($map, $key)</td>
<td>根据给定的 key 值判断 map 是否有对应的 value 值，如果有返回 true，否则返回 false</td>
</tr>
<tr>
<td>keywords($args)</td>
<td>返回一个函数的参数，这个参数可以动态的设置 key 和 value（不建议使用）</td>
</tr>
</tbody></table>
<h3 id="关于-keywords"><a href="#关于-keywords" class="headerlink" title="关于 keywords"></a>关于 keywords</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">@mixin foo($args...)&#123;</span><br><span class="line">    @debug keywords($args);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@include foo($arg1: &apos;abc&apos;, $arg2: &apos;efg&apos;);</span><br></pre></td></tr></table></figure>

<h2 id="自定义函数"><a href="#自定义函数" class="headerlink" title="自定义函数"></a>自定义函数</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- 实现rem和px的转换 --&gt;</span><br><span class="line">@function px2rem($px) &#123;</span><br><span class="line">    $rem: 37.5px;</span><br><span class="line"></span><br><span class="line">    @return ($px/$rem) + rem;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/10/25/Sass内置函数/" data-id="ck4r400rv008hl0w04gr4odde" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Sass/">Sass</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/10/28/React组件三大属性及组件通信/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          React组件三大属性及组件通信
        
      </div>
    </a>
  
  
    <a href="/2019/10/23/Sass基础/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Sass基础</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Ajax/">Ajax</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS/">CSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS3/">CSS3</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Dart/">Dart</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Flutter/">Flutter</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML/">HTML</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML5/">HTML5</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JSON/">JSON</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/QT/">QT</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/React/">React</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Sass/">Sass</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TypeScript/">TypeScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/bootstrap/">bootstrap</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Ajax/">Ajax</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS/">CSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS3/">CSS3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dart/">Dart</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Flutter/">Flutter</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML/">HTML</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML5/">HTML5</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JSON/">JSON</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Javascript/">Javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/QT/">QT</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sass/">Sass</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TypeScript/">TypeScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bootstrap/">bootstrap</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Ajax/" style="font-size: 12.22px;">Ajax</a> <a href="/tags/CSS/" style="font-size: 18.89px;">CSS</a> <a href="/tags/CSS3/" style="font-size: 17.78px;">CSS3</a> <a href="/tags/Dart/" style="font-size: 14.44px;">Dart</a> <a href="/tags/Flutter/" style="font-size: 16.67px;">Flutter</a> <a href="/tags/Git/" style="font-size: 12.22px;">Git</a> <a href="/tags/HTML/" style="font-size: 14.44px;">HTML</a> <a href="/tags/HTML5/" style="font-size: 12.22px;">HTML5</a> <a href="/tags/JSON/" style="font-size: 10px;">JSON</a> <a href="/tags/Java/" style="font-size: 11.11px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 20px;">JavaScript</a> <a href="/tags/Javascript/" style="font-size: 10px;">Javascript</a> <a href="/tags/QT/" style="font-size: 12.22px;">QT</a> <a href="/tags/React/" style="font-size: 15.56px;">React</a> <a href="/tags/Sass/" style="font-size: 11.11px;">Sass</a> <a href="/tags/TheKnowledgeOf/" style="font-size: 11.11px;">TheKnowledgeOf</a> <a href="/tags/TypeScript/" style="font-size: 10px;">TypeScript</a> <a href="/tags/bootstrap/" style="font-size: 11.11px;">bootstrap</a> <a href="/tags/jQuery/" style="font-size: 13.33px;">jQuery</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">July 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">May 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/12/29/Flutter-MaterialApp常用属性介绍/">Flutter-MaterialApp常用属性介绍</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-ListView/">Flutter-ListView</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-AppBar/">Flutter-AppBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-TabBar/">Flutter-TabBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-按钮/">Flutter-按钮</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>